package com.example.springbaitthymeleafdemo.controller;

import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

@Controller
public class ThymeleafController {
    @RequestMapping("/hello")
    public String hello(Model model){
        model.addAttribute("msg","Hello thymeleaf world!");
        return "hello";
    }

    @RequestMapping("demo")
    public String thymeleaf(ModelMap map, HttpSession session){
        map.put("thText","th:text <b>加粗</b>");
        map.put("thUText","th:utext <b>加粗</b>");
        map.put("thValue","thValue");
        map.put("thEach", Arrays.asList("th:each", "遍历列表"));
        map.put("thIf",null);
        map.put("itdragonStr","stringssssdfd");
        map.put("itdragonNum",100.8977);
        map.put("itdragonBool",false);
        String[] arrayData = {"x","-1","0","1","9","10","11"};
        map.put("itdragonArray",arrayData);
        List<String> itdragonList = new ArrayList<>();
        itdragonList.add("1");
        itdragonList.add("2");
        itdragonList.add("3");
        map.put("itdragonList",itdragonList);
        Map<String,Object> itdragonMap = new HashMap<>();
        itdragonMap.put("name","张三");
        itdragonMap.put("age","28");
        itdragonMap.put("sex","男");

        map.put("itdragonMap",itdragonMap);
        map.put("thObject",new Person());
        map.put("itdragonDate",new Date());
        map.put("person",new Person());
        return "demo";
    }

    @RequestMapping("/formDemo")
    @ResponseBody
    public String hello(@ModelAttribute Person person){
        System.out.println();
        return "person";
    }
}
